package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.ProductStore;
import com.example.demo.entity.UserProductinfo;
import com.example.demo.service.UserProductinfoService;
import com.example.demo.mapper.UserProductinfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 18364
* @description 针对表【user_productInfo】的数据库操作Service实现
* @createDate 2024-11-26 16:33:16
*/
@Service
public class UserProductinfoServiceImpl extends ServiceImpl<UserProductinfoMapper, UserProductinfo>
    implements UserProductinfoService{
    @Autowired
    UserProductinfoMapper userProductinfoMapper;

    @Override
    public UserProductinfo selectProductInfoOne(String userId, String appId, String trainingId) {
        QueryWrapper<UserProductinfo> queryWrapper=new QueryWrapper<>();
        if(userId!=null){
            queryWrapper.eq("userId",userId);
        }
        if(trainingId!=null){
            queryWrapper.eq("trainingId",trainingId);
        }
        if(appId!=null){
            queryWrapper.eq("appId",appId);
        }
        queryWrapper.orderByDesc("id");
        List<UserProductinfo> l=userProductinfoMapper.selectList(queryWrapper);
        if(l.size()>0){
            return l.get(0);
        }
        return null;
    }

    @Override
    public List<UserProductinfo> selectProductInfo(String userId, String appId, String trainingId) {
        QueryWrapper<UserProductinfo> queryWrapper=new QueryWrapper<>();
        if(userId!=null){
            queryWrapper.eq("userId",userId);
        }
        if(trainingId!=null){
            queryWrapper.eq("trainingId",trainingId);
        }
        if(appId!=null){
            queryWrapper.eq("appId",appId);
        }
        queryWrapper.orderByDesc("id");
        return userProductinfoMapper.selectList(queryWrapper);
    }

    @Override
    public Integer deleteByInfo(String userId, String appId, String trainingId) {
        QueryWrapper<UserProductinfo> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("userId",userId);
        if(appId!=null){
            queryWrapper.eq("appId",appId);
        }
        queryWrapper.eq("trainingId",trainingId);
        queryWrapper.orderByDesc("id");
        return userProductinfoMapper.delete(queryWrapper);
    }

    @Override
    public UserProductinfo selectByModel(String userId, String appId, String trainingId, String productModel) {
        QueryWrapper<UserProductinfo> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("userId",userId);
        queryWrapper.eq("appId",appId);
        queryWrapper.eq("trainingId",trainingId);
        queryWrapper.eq("productModel",productModel);
        queryWrapper.orderByDesc("id");
        return userProductinfoMapper.selectOne(queryWrapper);
    }

    @Override
    public UserProductinfo selectById(Integer id) {

        return userProductinfoMapper.selectById(id);
    }


}




